//
// Created by gogoqiu on 2021/8/25.
//

#ifndef WXTEST_PREFERENCESFRAME_H
#define WXTEST_PREFERENCESFRAME_H

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/listbox.h>

#include "../data/Preference.h"
#include "../PreferenceScreen.h"
#include "../MyTagApp.h"

/*
 * adapter
 *  setItems
 *
 * */
class ListItemPanel: public wxPanel{
public:
    ListItemPanel( wxWindow *parent, PreferenceView *view ):
            wxPanel( parent ) {
        SetBackgroundColour( wxColour( 0, 128, 192 ) );
        //Panel root size
        auto *innerSizer = new wxBoxSizer(wxVERTICAL);
        //titleSizer = new wxBoxSizer(wxHORIZONTAL);
        //
        auto * titleCtrl = new wxStaticText( this,  wxID_ANY, view->getTitle(),
                                             wxDefaultPosition, wxDefaultSize, 0 );
        //
        innerSizer->Add( titleCtrl, 1,
                         wxALL|wxALIGN_LEFT, 10);
        //last updated value
        auto* statusCtrl = new wxStaticText( this,  wxID_ANY, view->getValue(),
                                             wxDefaultPosition, wxDefaultSize, 0 );
        innerSizer->Add( statusCtrl, 1,
                         wxALL|wxALIGN_CENTER_HORIZONTAL, 4);
        view->setControl(statusCtrl);

        SetSizer( innerSizer );
        Layout();
    }
};

//
class PreferenceAdapter;

/**
 * main framework
 */
class PreferencesFrame : public wxFrame
{
public:
    /*
     * data update
     * objects
     * View
     * getCurrentValue
     * load the table
     * build the view items
     * dialog
     * 只有value是变化的
     */
    PreferencesFrame( wxWindow *parent, MyTagApp *myTagApp );
    ~PreferencesFrame() override;
private:
    MyTagApp * myTagApp;
    vector<wxPanel*> panels;
    PreferenceAdapter *mPreferenceAdapter;
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void BuildView( );
    int idx;
    void request();
    /*
     * layout:
     *  list: sizeBox(v)
     *      panel
     *          sizeBox(v)
     *              //sizeBox(h)
     *                  title//, wxSpace, input:value
     *              statusCtrl
     */
    wxPanel *m_panel;
    //listBox sizer
    wxBoxSizer *panelRootBoxSizer;
    wxBoxSizer *dialogRootBoxSizer;
    wxScrolledWindow* m_listbox;
    //void OnClickItem(wxCommandEvent& event);
    virtual void OnClickItem( wxMouseEvent& event );

    void OnClose( wxCloseEvent&  event );

    void OnActionEvent(wxCommandEvent &event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
    ID_Hello = 1
};


#endif //WXTEST_PREFERENCESFRAME_H
